<!--
 * @Author: daidai
 * @Date: 2022-02-20 16:16:42
 * @LastEditors: Please set LastEditors
 * @LastEditTime: 2022-10-25 09:18:22
 * @FilePath: \web-pc\src\pages\big-screen\view\indexs\left-center.vue
-->
<template>
  <Echart v-if="pageflag" :options="options" class="left_center_inner" ref="charts" height="250px" isClick
    @chartClick="chartClick" />
  <Reacquire v-else @onclick="getData" style="line-height: 200px">
    重新获取
  </Reacquire>
</template>

<script>
import { colorsA, colorsB, legend, xAxis, yAxis } from '@/config/EChartVar';
import { graphic } from 'echarts';
export default {
  data() {
    return {
      options: {},
      countUserNumData: {
        axisData: ['大集物流园', '兰华物流园', '兰田物流港', '华苑物流城', '华丰物流城'],
        seriesData: [36, 42, 40, 39, 35],
        seriesData1: [42, 41, 39, 39, 38],
        seriesDataBg: [48, 24, 48, 20, 49],
      },
      pageflag: true,
      timer: null,
      chartType: 0,
      autoTimer: null,
      series: [],

    };
  },
  created() {
    this.getData();
  },
  mounted() { },
  beforeDestroy() {
    this.clearData();
  },
  methods: {
    autoChange() {
      this.options.series = this.chartType >= 2 ? this.series : this.series[this.chartType];
      if (this.chartType >= 2) {
        this.chartType = 0;
      } else {
        this.chartType += 1;
      }
    },
    autoSwitper() {
      if (this.autoTimer) {
        return;
      }
      let looper = (a) => {
        this.autoChange();
      };
      this.autoTimer = setInterval(
        looper,
        3000
      );
    },
    chartClick(params) {
      this.$emit('chartClick', params);
    },
    clearData() {
      if (this.timer) {
        clearInterval(this.timer);
        this.timer = null;
      }
    },
    getData() {
      this.pageflag = true;
      this.init(this.countUserNumData);

      this.autoSwitper();
    },
    init(currentData) {
      let axisData = currentData.axisData;
      let seriesData = [
        [...currentData.seriesData],
        [...currentData.seriesData1],
        [...currentData.seriesDataBg],
      ];
      const options = {
        grid: {
          top: '20%',
          left: '4%',
          right: '4%',
          bottom: '12%',
          containLabel: true,
        },
        legend: {
          show: true,
          top: '0%',
          right: '9%',
          icon: 'rect',
          itemWidth: 12,
          itemHeight: 6,
          // itemGap: 60,
          textStyle: legend.textStyle,
          data: ['入园', '出园'],
        },
        xAxis: {
          type: 'category',
          data: axisData,
          // boundaryGap: false,
          // boundaryGap: true,
          splitLine: {
            show: false,
          },
          axisTick: {
            show: false, // 不显示下切线
          },
          axisLabel: xAxis.axisLabel,
          axisLine: {
            lineStyle: {
              background: 'rgba(176, 215, 255, 0.4)',
            },
          },
        },
        yAxis: [
          {
            type: 'value',
            // max: 50,
            // min: 20,//
            // interval: 5,
            axisLabel: yAxis.axisLabel,
            axisLine: {
              show: false,
              // interval: 1,
              lineStyle: {
                color: 'rgba(0,0,0,0.5)',
              },
            },
            splitLine: {
              show: true,
              // interval: 1,
              lineStyle: {
                color: ['rgba(176, 215, 255, 0.2)'],
                width: 1,
                type: 'dashed',
              },
            },
            // splitLine: {
            //   show: false,
            // },
            axisTick: {
              show: false,
            },
          },
        ],
        series: [],
      };
      const series = [
        {
          name: '入园',
          type: 'line',
          // 动画配置
          animation: true,
          animationDuration: 2000,
          animationEasing: 'quarticInOut',
          animationDelay: function (idx) {
            return idx * 150;
          },
          smooth: false,
          showSymbol: false,
          data: seriesData[0],
          itemStyle: {
            normal: {
              // color: "#38FFBA",
              color: '#00D5FF',
            },
          },
          // areaStyle: {
          //   color: colorsB[0],
          // },
          lineStyle: {
            normal: {
              width: 2,
            },
          },
          label: {
            show: false,
          },
        },
        {
          name: '出园',
          type: 'line',
          // 动画配置
          animation: true,
          animationDuration: 2000,
          animationEasing: 'quarticInOut',
          animationDelay: function (idx) {
            return idx * 150;
          },
          smooth: false,
          showSymbol: false,
          itemStyle: {
            normal: {
              color: '#1978E5',
              // color: 'rgba(0,219,254, .7)',
            },
          },
          data: seriesData[1],
          lineStyle: {
            normal: {
              width: 2,
            },
          },
        }
      ];
      options.series = series;
      this.series = [...series];
      this.options = options;
    },
  },
};
</script>
<style lang="scss" scoped>
.list {
  margin: 5px 20px 15px 20px;

  .list-header {
    border: 1px solid #153c81;
    display: flex;
    justify-content: center;
    height: 32px;
    line-height: 32px;
    color: rgba($color: #ffffff, $alpha: 0.8);

    .first {
      width: 55%;
      text-align: center;
      margin-left: -10%;
    }

    .last {
      padding-left: 20px;
    }
  }

  .list-item {
    border: 1px solid #153c81;
    margin-top: 10px;
    display: flex;
    justify-content: space-around;
    align-items: center;
    height: 32px;
    line-height: 32px;
    color: rgba($color: #ffffff, $alpha: 0.9);
    font-weight: bold;

    .first {
      // position: relative;
      width: 55%;
      display: flex;
      justify-content: space-around;
      align-items: center;

      &::before {
        // position: absolute;
        // left: -52px;
        // top: 2px;
        // content: url('../../assets/img/launch/inout/icon.png');
      }

      .no {
        position: relative;
        left: -30px;
        top: 0px;
        width: 25px;
        height: 24px;
        background: url('../../../assets/img/launch/home/icon.png') no-repeat 1% 50%;
        display: flex;
        justify-content: center;
        align-items: center;
      }

      .spanText {
        display: flex;
        justify-content: center;
        text-align: center;
      }
    }

    .last {
      width: 45%;
      text-align: center;
    }
  }
}
</style>
